********************************************************************************
** *TABLE 5: Mobile Balances (HIGH HOPES)
********************************************************************************
set more off
use "$merge_mobile", clear 





*Setting locals for outcomes by date 
loc admin_varlist5 "mobile_balance_jan5  dummy_150 dummy_200 cba_srvy_jan5 cba_srvy_jan31 gross_srvy_jan5 gross_srvy_jan31 fin_savings_jan5 fin_savings_jan31"


estimates clear
foreach var of varlist `admin_varlist5' {	

	*** Mshwari instrumented with treatment1 and treatment2 ; all sample
	
	*ITT
	xi: reg `var' mshwariorlsa treatment2 i.stratification b_primaryormore b_secondaryormore b_age_imp b_age_imp2 b_age_imp_dummy b_mpesastatus nb_children_imp mobile_balance_june30, cluster(b_schoolname_baseline_encoded) 
 	summ `var' if e(sample)==1 & control==1 
	estadd local R2 = string(e(r2), "%9.2f")
	estadd local R2a = string(e(r2_a), "%9.2f")
	estadd local cmean=string(r(mean), "%9.2f")
	estimates store `var'_ITT		
	*TOT
	xi: ivreg2 `var' (mshwari_after lsa_after=mshwariorlsa treatment2) i.stratification b_primaryormore b_secondaryormore b_age_imp b_age_imp2 b_age_imp_dummy b_mpesastatus nb_children_imp mobile_balance_june30, cluster(b_schoolname_baseline_encoded) 
	estadd local Papp=string(e(widstat), "%9.0f")
	estadd local PappLM=string(e(idstat), "%9.0f")
	estadd local R2 = string(e(r2), "%9.2f")
	estadd local R2u = string(e(r2u), "%9.2f")
	estadd local R2a = string(e(r2_a), "%9.2f")
	summ `var' if e(sample)==1 & control==1 
	estadd local cmean=string(r(mean), "%9.2f")
	estimates store `var'_TOT
	
}

*Esttab
	*ITT
	local tablist ""
	foreach var in `admin_varlist5' {
	local i `var'_ITT 
	local tablist "`tablist' `i'"
	}
	#delimit ;
	esttab `tablist' using "$output/Table_05_Savings_PanelA.csv",
	replace 
	nolines nogaps nonotes nomtitles nodepvars noobs
	drop(_Istratific_* _cons)
	scalars("R2a Adjusted R-Squared")
	b(%9.2f) se(%9.2f) 
	starlevels(* 0.1 ** 0.05 *** 0.01)
	obslast legend label collabels(none) 
	mgroups( "Mobile Balance" "CBA Gross Savings" "Gross Mobile Savings" "Gross Financial Savings", pattern(1 0 0 1 0 1 0 1 0 ) ) ;
	#delimit cr	

	* TOT
	local tablist ""
	foreach var in `admin_varlist5' {
	local i `var'_TOT 
	local tablist "`tablist' `i'"
	}
	#delimit ;
	esttab `tablist' using "$output/Table_05_Savings_PanelB.csv",
	replace 
	nolines nogaps nonotes nomtitles nodepvars 
	drop(_Istratific_* _cons)
	scalars("Papp F-Statistic for weak identification"  
	"R2a  Adjusted R-squared" "cmean Control Mean" )
	b(%9.2f) se(%9.2f) 
	starlevels(* 0.1 ** 0.05 *** 0.01)
	obslast legend label collabels(none) 
	mgroups( "Mobile Balance" "CBA Gross Savings" "Gross Mobile Savings" "Gross Financial Savings", pattern(1 0 0 1 0 1 0 1 0 ) ) ;
	#delimit cr	
	
	


****calculate MBA/LSA complier's' mean in control



**MBA 	
gen mba=.
replace mba=1 if treatment_arm==1 | treatment_arm==2
replace mba=0 if treatment_arm==0

//syntax comp_mean_TOT dep_var treat_var compliance_var
foreach var of varlist `admin_varlist5' {
	
	comp_mean_TOT `var' mba mshwari_after 
	
}	

*LSA
drop lsa
gen lsa = .
replace lsa=1 if treatment_arm==2
replace lsa=0 if treatment_arm==0

foreach var of varlist `admin_varlist5' {
	
	comp_mean_TOT `var' lsa lsa_after 
	
}	

exit


Notes: MBA exposure =1 if MBA treatment=1 OR LSA treatment=1.   LSA exposure=1 if  MBA treatment=0 and LSA treatment=1.  The coefficient on LSA exposure reflects the marginal impact of exposure to the LSA relative to exposure to the MBA.  Columns 1-3 report mobile balances (Jan5)  and indicators for mobile balances greater than 15,000 KSh. and 20,000 KSh. Gross CBA Savings = MBA savings + LSA savings; Gross Mobile Savings = M-PESA savings + MBA savings + LSA savings.  These savings variables are calculated using administrative data available between recruitment and January 31 and the sample is restricted to those with ADS consent. Gross Financial Savings calculated using endline data (Bank Account + Mattress Saving + SACCO + CHAMA + Advanced Purchases + Family + Other) and administrative data (Gross Mobile Savings). All missing outcome components from endline are treated as zeros. Sample restricted to those with ADS consent and found at endline.  Robust standard errors clustered at school level.  Control variables include number of children, Mobile Balance (June 30th), a quadratic in respondent's age and indicator variables for primary, secondary school completion and M-PESA use at baseline.  *** significant at 1%, ** significant at 5%, * significant at 10%. 


		